from django.db import models

# Create your models here.

from django.contrib.auth.models import AbstractUser


#2025-2-7 shp 重新定义用户表
class UserProfile(AbstractUser):
    avatar = models.ImageField(upload_to='image/avatar', default='', max_length=100, null=True, blank=True)
    nick_name = models.CharField(max_length=20, verbose_name=u'姓名', default=u'新用户')
    birthday = models.DateTimeField(verbose_name=u'生日', null=True, blank=True)
    gender = models.CharField(choices=(('man', u'男'), ('woman', u'女')), max_length=8, default='man' )
    wechat = models.CharField(max_length=100, default=u'微信号', null=True,blank=True , verbose_name=u'微信号')
    mobile = models.CharField(max_length=11, verbose_name='联系方式', null=True, blank=True, default='')
    address = models.CharField(max_length=100, verbose_name='住址', null=True, blank=True, default='')
    positionid = models.IntegerField( verbose_name='职务id', null=True, blank=True)
    departmentid =  models.IntegerField( verbose_name='部门id', null=True, blank=True)
    class Meta:
        verbose_name = u'用户'
        verbose_name_plural = verbose_name

#2025-02-08 shp 定义职务表
class positions(models.Model):
    positionname = models.CharField(max_length=50, verbose_name='职务名称', null=True,blank=True,)
    description = models.CharField(max_length=50, verbose_name='职务描述', null=True)
    level = models.CharField(max_length=50, verbose_name='职务等级', null=True)
    tlid =models.IntegerField(verbose_name='关联差旅报销单id', null=True, blank=True, )
    create_name = models.CharField(max_length=50, verbose_name='创建人', null=True, blank=True, )
    edit_name = models.CharField(max_length=50, verbose_name='修改人', null=True, blank=True, )
    create_time = models.DateTimeField(verbose_name='创建时间', null=True, blank=True, auto_now_add=True)
    edit_time = models.DateTimeField(verbose_name='修改时间', null=True, blank=True, auto_now=True)

#2025-02-08 shp 定义部门表
class departments(models.Model):
    departmentname = models.CharField(max_length=50, verbose_name='部门名称', null=True, blank=True, )
    manager = models.CharField(max_length=50, verbose_name='部门经理', null=True, blank=True, )
    create_name = models.CharField(max_length=50, verbose_name='创建人', null=True, blank=True, )
    edit_name = models.CharField(max_length=50, verbose_name='修改人', null=True, blank=True, )
    create_time = models.DateTimeField(verbose_name='创建时间', null=True, blank=True, auto_now_add=True)
    edit_time = models.DateTimeField(verbose_name='修改时间', null=True, blank=True, auto_now=True)

#2025-02-08 shp 定义差旅费报销表
class travelreimburse(models.Model):
    name = models.CharField(max_length=50, verbose_name='名称',  blank=True, )
    ticket =  models.DecimalField(max_digits=6, decimal_places=2, verbose_name='机、车、船票', null=True, blank=True, )
    cityticket = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='市内交通费单据', null=True, blank=True, )
    quarterage = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='住宿费', null=True, blank=True, )
    foodallowance= models.DecimalField(max_digits=6, decimal_places=2, verbose_name='伙食补助', null=True, blank=True, )
    other_1 = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='其他1', null=True, blank=True, )
    other_2 = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='其他2', null=True, blank=True, )
    other_3 = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='其他3', null=True, blank=True, )
    othername_1 = models.CharField(max_length=50, verbose_name='其他名称1', null=True, blank=True, )
    othername_2 = models.CharField(max_length=50, verbose_name='其他名称2', null=True, blank=True, )
    othername_3 = models.CharField(max_length=50, verbose_name='其他名称3', null=True, blank=True, )
    reforBu_trip = models.CharField(max_length=50, verbose_name='出差事由', null=True, blank=True, )
    total = models.CharField(max_length=50, verbose_name='合计', null=True, blank=True, )
    userid  = models.IntegerField( verbose_name='账号id', null=True, blank=True, )
    create_name =  models.CharField(max_length=50, verbose_name='创建人', null=True, blank=True, )
    edit_name = models.CharField(max_length=50, verbose_name='修改人', null=True, blank=True, )
    create_time = models.DateTimeField(verbose_name='创建时间', null=True, blank=True, auto_now_add=True)
    edit_time = models.DateTimeField(verbose_name='修改时间', null=True, blank=True, auto_now=True)

#2025-02-08 shp 定义差旅报销关联表
class travelreimburseordel(models.Model):
    travel_Reimburse_id = models.IntegerField(verbose_name='关联差旅报销单id', null=True, blank=True, )
    start_time = models.DateTimeField(verbose_name='开始时间', null=True, blank=True, )
    end_time = models.DateTimeField(verbose_name='结束日期', null=True, blank=True, )
    start_location = models.CharField(max_length=50, verbose_name='开始地点', null=True, blank=True, )
    end_location = models.CharField(max_length=50, verbose_name='结束地点', null=True, blank=True, )
    comment = models.CharField(max_length=50, verbose_name='备注', null=True, blank=True, )
    days_in_transit = models.DecimalField(max_digits=6, decimal_places=2,verbose_name='在途天数', null=True, blank=True, )
    money = models.DecimalField(max_digits=7, decimal_places=2,verbose_name='金额', null=True, blank=True, )
    stayperiod =  models.DecimalField(max_digits=7, decimal_places=2,verbose_name='住勤天数', null=True, blank=True, )
    create_name =  models.CharField(max_length=50, verbose_name='创建人', null=True, blank=True, )
    edit_name = models.CharField(max_length=50, verbose_name='修改人', null=True, blank=True, )
    create_time = models.DateTimeField(verbose_name='创建时间', null=True, blank=True, auto_now_add=True)
    edit_time = models.DateTimeField(verbose_name='修改时间', null=True, blank=True, auto_now=True)

#2025-02-11 shp 定义出差补贴表
class travelallowance(models.Model):
    dailymeal = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='伙食补贴标准', null=True,
                                    blank=True, )
    citytransport = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='市内交通补贴（可能按天或固定金额）', null=True,
                                        blank=True, )
    lowsubsidy = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='淡季住宿补贴(1,2,3,4,5,11,12)', null=True,
                                          blank=True, )
    highsubsidy = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='旺季住宿补贴(6,7,8,9,10', null=True,
                                          blank=True, )
    create_name =  models.CharField(max_length=50, verbose_name='创建人', null=True, blank=True, )
    edit_name = models.CharField(max_length=50, verbose_name='修改人', null=True, blank=True, )
    create_time = models.DateTimeField(verbose_name='创建时间', null=True, blank=True, auto_now_add=True)
    edit_time = models.DateTimeField(verbose_name='修改时间', null=True, blank=True, auto_now=True)
#2025-04-27 shp 自定义链接
class framemenu(models.Model):
    title = models.CharField(max_length=50, verbose_name='菜单名称', null=True, blank=True, )
    parent_id = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='父级菜单ID（0表示根节点）', null=True,
                                    blank=True, )
    menu_id = models.CharField(max_length=5, verbose_name='菜单唯一标识', null=True, blank=True, )
    path = models.CharField(max_length=50, verbose_name='路由地址', null=True, blank=True, )
    sort_order = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='子节点顺序', null=True,
                                    blank=True, )
    permission_level = models.PositiveIntegerField(verbose_name='权限等级',default=1,  # 默认权限级别为1
        help_text='权限越大，可见性越高（例如：1-普通用户，2-管理员，3-超级管理员）'
    )
    create_name =  models.CharField(max_length=50, verbose_name='创建人', null=True, blank=True, )
    edit_name = models.CharField(max_length=50, verbose_name='修改人', null=True, blank=True, )
    create_time = models.DateTimeField(verbose_name='创建时间', null=True, blank=True, auto_now_add=True)
    edit_time = models.DateTimeField(verbose_name='修改时间', null=True, blank=True, auto_now=True)

#2025-04-29 shp 父级菜单
class parentmenu(models.Model):
    fratitle = models.CharField(max_length=50, verbose_name='菜单名称', null=True, blank=True, )
    sort_order = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='父节点顺序', null=True,
                                    blank=True, )
    create_name =  models.CharField(max_length=50, verbose_name='创建人', null=True, blank=True, )
    edit_name = models.CharField(max_length=50, verbose_name='修改人', null=True, blank=True, )
    create_time = models.DateTimeField(verbose_name='创建时间', null=True, blank=True, auto_now_add=True)
    edit_time = models.DateTimeField(verbose_name='修改时间', null=True, blank=True, auto_now=True)

#2025-5-8 shp 商户基本信息
class merchantinfo(models.Model):
    name = models.CharField(max_length=50, verbose_name='商户名称', null=True, blank=True, )
    merchant_full_name = models.CharField(max_length=50, verbose_name='商户全称', null=True, blank=True,
                            help_text='商户全称' )
    industry = models.CharField(max_length=20, verbose_name='商户类型', null=True, blank=True,
                            help_text='商户类型' )
    amount = models.DecimalField(
        max_digits=10,  # 支持更大金额范围
        decimal_places=2,
        verbose_name='交易金额',
        help_text='正数表示收入，负数表示退款'
    )

    amount_status = models.CharField(
        max_length=20,
        verbose_name='金额状态',
        choices=[
            ('success', '支付成功'),
            ('failed', '支付失败'),
            ('refund', '已退款')
        ],
        default='success'
    )
    payment_type = models.CharField(
        max_length=20,
        verbose_name='支付方式',
        help_text='如: 建设银行储蓄卡(8166)',
        null=True,
        blank=True
    )
    payment_time = models.DateTimeField(verbose_name='支付时间', null=True, blank=True, auto_now=True,
                                     help_text='支付时间', auto_now_add=False    )
    product = models.CharField(max_length=20, verbose_name='商品名称', null=True, blank=True,
                            help_text='商品名称' )
    transaction_no = models.CharField(max_length=20, verbose_name='交易单号', null=True, blank=True,
                            help_text='交易单号' )
    merchant_order_no = models.CharField(max_length=20, verbose_name='商户单号', null=True, blank=True,
                            help_text='商户单号' )
    audit_status = models.CharField(max_length=20, verbose_name='ocr审核状态', null=True, blank=True,
                            help_text='ocr审核状态 （0-待审核，1-已通过，2-已拒绝）' )
    userid = models.IntegerField(verbose_name='账号id', null=True, blank=True, )
    create_name =  models.CharField(max_length=50, verbose_name='创建人', null=True, blank=True, )
    edit_name = models.CharField(max_length=50, verbose_name='修改人', null=True, blank=True, )
    create_time = models.DateTimeField(verbose_name='创建时间', null=True, blank=True, auto_now_add=True)
    edit_time = models.DateTimeField(verbose_name='修改时间', null=True, blank=True, auto_now=True)
    class Meta:
        verbose_name = '商户交易记录'
        verbose_name_plural = '商户交易记录'
        ordering = ['-payment_time']  # 默认按支付时间倒序排列

    def __str__(self):
        return f"{self.merchant_full_name} - {self.transaction_no}"